<?
session_start();
include('conn.php');
$qry1 = "SELECT * FROM Customer c right join STBtoCustomer sc on c.CustId = sc.CustId 
		where sc.status='1' and sc.TerminationDate is null order by sc.stbtocustid desc;";

$qry = mysql_query($qry1);
$data = array();
$i=1;
while($rows = mysql_fetch_array($qry))
{
	$q1 = "select societyname from society where socId = '".$rows['socId']."'";
	$r1 = mysql_fetch_array(mysql_query($q1));
	
	$q2 = "select stbno,cardno from stbTable s,cardTable c where s.id in (select stbid from STBDetails where pairid='".$rows['pairid']."') and c.id in (select cardid from STBDetails where pairid='".$rows['pairid']."');";
	$r2 = mysql_fetch_array(mysql_query($q2));
	
	$data[] = array
		(				
			"id" => $rows['stbtocustid'],
			"saf" => $rows['SAFno'],
			"sname" => $r1['societyname'],
			"room" => $rows['RoomNumber'],
			"cname" => $rows['CustomerName'],
			"ph" => $rows['TelNo'],
			"email" => $rows['Email'],
			"rpm" => $rows['RateperMonth'],
			"stb" => $r2['stbno'],
			"card" => $r2['cardno'],
			"actdt" => $rows['ActivationDate'],
			"termdt" => $rows['TerminationDate']			
		);
}
echo json_encode($data);
?>